package com.gochart.controller;

import com.gochart.bean.User;
import com.gochart.dao.UserDao;
import org.apache.http.HttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by shaxj on 16/6/25.
 */
@Controller
@RequestMapping("/loginServer")
public class LoginController {

    @Autowired
    private UserDao userDao;

    @RequestMapping(value = "login", method = RequestMethod.POST, produces= MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String,Object> login(ModelMap model,HttpServletRequest request) {
        model.addAttribute("message", "Hello world!");
        System.out.println("model = " + model);
        User table = userDao.getById("1");
        model.addAttribute("table", table);
        System.out.println("table = " + table);
        Map<String,Object> result = new HashMap<>();
        result.put("user",table);
        return result;
    }


    @RequestMapping(value = "register", method = RequestMethod.POST)
    public Map<String,Object> register(ModelMap model) {
        model.addAttribute("message", "Hello world!");
        System.out.println("model = " + model);
        User table = userDao.getById("");

        Map<String,Object> result = new HashMap<>();
        result.put("user",table);
        return result;
    }
}
